package com.zyh.day02.keyvalue

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object AggregateByKeyTest {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setAppName("m")
      .setMaster("local[*]")
    val sc = new SparkContext(conf)
    val rdd1: RDD[(String,Int)] = sc.makeRDD(List(("female",1),("male",5),("female",1),("female",5),("male",2),("male",1)),2)
    val rdd2: RDD[(String, Int)] = rdd1.aggregateByKey(0)((v1, v2) => v1 + v2, (v1, v2) => v1 + v2)
    rdd2.foreach(println)
    sc.stop()
  }
}
